﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Pavilion;
using Pavilion.Control;

namespace PavilionGame
{
    public class HomeView : IView
    {
        private NarrativeMenu narrativeMenu;
        private Button narrativeButton, arenaButton, optionsButton, exitButton;
        private Game game;

        public HomeView(Game game)
        {
            this.game = game;
        }

        private void InitializeControls()
        {
            narrativeMenu = new NarrativeMenu(new Rectangle(GameEngine.WindowWidth / 2 - 300, GameEngine.WindowHeight / 2 - 200, 600, 400));
            narrativeButton = new Button("Narrative", new Rectangle(70, 495, 120, 40), 0.5f);
            arenaButton = new Button("Arena", new Rectangle(70, 540, 120, 40), 0.5f);
            optionsButton = new Button("Options", new Rectangle(70, 585, 120, 40), 0.5f);
            exitButton = new Button("Exit", new Rectangle(70, 630, 120, 40), 0.5f);

            narrativeButton.Pressed += new Action(Narrative_ButtonPressed);
            exitButton.Pressed += new Action(Exit_ButtonPressed);
            narrativeMenu.ClosePressed += new Action(narrativeMenu_ClosePressed);
        }

        public void Load(GameSession gameSession)
        {
            InitializeControls();
            narrativeMenu.Visible = false;

            RootControl.Instance.Collection.Add(narrativeButton);
            RootControl.Instance.Collection.Add(arenaButton);
            RootControl.Instance.Collection.Add(optionsButton);
            RootControl.Instance.Collection.Add(exitButton);
            RootControl.Instance.Collection.Add(narrativeMenu);
        }

        public void Unload()
        {
            narrativeButton.Pressed -= new Action(Narrative_ButtonPressed);
            exitButton.Pressed -= new Action(Exit_ButtonPressed);
            narrativeMenu.ClosePressed -= new Action(narrativeMenu_ClosePressed);

            narrativeMenu.Dispose();

            RootControl.Instance.Clear();
        }

        public void Update(GameTime gameTime)
        {
            RootControl.Instance.Update(gameTime);
        }

        public void Draw()
        {
            RootControl.Instance.Draw();
            DrawManager.Instance.DrawTextOnScreen("[Game Title Goes Here]", new Vector2(GameEngine.WindowWidth / 2, 75), Color.Black, 1f, true);
        }

        private void narrativeMenu_ClosePressed()
        {
            narrativeMenu.Visible = false;
            narrativeButton.Enabled = true;
        }

        private void Narrative_ButtonPressed()
        {
            narrativeMenu.Visible = true;
            narrativeButton.Enabled = false;
        }

        private void Exit_ButtonPressed()
        {
            game.Exit();
        }
    }
}
